package it.openHWHackaton.Match;


import java.util.Date;

import twitter4j.TwitterException;

public class Match {
	private String stadium;
	private Team team1;
	private Team team2;
	private Date startMatch;
	private int scoreTeam1;
	private int scoreTeam2;

	public Match() {
		super();
	}

	public Match(String stadium, Team team1, Team team2) {
		super();
		this.stadium = stadium;
		this.team1 = team1;
		this.team2 = team2;
		this.scoreTeam1=0;
		this.scoreTeam2=0;
		this.startMatch=new Date();
	}


	public void startMatch(){
		String startMsg="Welcome to "+this.stadium+" stadium, today's match "+this.team1.getNomeTeam()+" Team vs "+this.team2.getNomeTeam()+" Team";
		RAtableSoccerAccount tw= new RAtableSoccerAccount();
		try {
			tw.sendTweet(startMsg);

		} catch (TwitterException e) {
			e.printStackTrace();
		}

		System.out.println(startMsg);
	}


	public void endMatch(){

		RAtableSoccerAccount tw= new RAtableSoccerAccount();
		try {
			tw.sendTweet("final score \n"+team1.getNomeTeam()+"-"+team2.getNomeTeam()+" "+getScoreTeam1()+" : "+getScoreTeam2());

		} catch (TwitterException e) {
			e.printStackTrace();
		}

		System.out.println("final score \n"+team1.getNomeTeam()+"-"+team2.getNomeTeam()+" "+getScoreTeam1()+" : "+getScoreTeam2());  


	}

	public void score(String team){     

		String msg="GOAL! ";

		Team currTeam=null;
		if(team.equals("1")){
			currTeam=team1;
			setScoreTeam1(getScoreTeam1()+1);
		}
		else if(team.equals("2")){
			currTeam=team2;
			setScoreTeam2(getScoreTeam2()+1);
		}
		String player=" ("+currTeam.getPlayer1().getTwitterName()+" - "+currTeam.getPlayer2().getTwitterName()+" )";

		RAtableSoccerAccount tw= new RAtableSoccerAccount();
		try {
			tw.sendTweet(msg+currTeam.getNomeTeam()+player+"\n"+getScore());

		} catch (TwitterException e) {
			e.printStackTrace();
		}
		System.out.println(msg+currTeam.getNomeTeam()+player+"\n"+getScore()); 
	}

	public String getScore(){
		return team1.getNomeTeam()+" "+getScoreTeam1()+" - "+getScoreTeam2()+" "+team2.getNomeTeam();
	}




	public void setScoreTeam1(int scoreTeam1) {
		this.scoreTeam1 = scoreTeam1;
	}

	public int getScoreTeam1() {
		return scoreTeam1;
	}

	public void setScoreTeam2(int scoreTeam2) {
		this.scoreTeam2 = scoreTeam2;
	}

	public int getScoreTeam2() {
		return scoreTeam2;
	}

	public String getStadium() {
		return stadium;
	}

	public void setStadium(String stadium) {
		this.stadium = stadium;
	}

	public Team getTeam1() {
		return team1;
	}

	public void setTeam1(Team team1) {
		this.team1 = team1;
	}

	public Team getTeam2() {
		return team2;
	}

	public void setTeam2(Team team2) {
		this.team2 = team2;
	}
	
	
}
